package question1;

import java.io.File;

public class CountType {
    public static void count(File file){
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;

        File[] files = file.listFiles();
        if(files.length == 0 || files == null){
            return;
        }
        for(File file1
        :files) {
            if (file1.isFile() && file1 != null) {
                int potIndex = file1.getPath().lastIndexOf(".");
                String str = file1.getPath().substring(potIndex + 1);
                if (str.equals("java")) {
                    count1++;
                } else if (str.equals("doc")) {
                    count2++;
                } else if (str.equals("txt")) {
                    count3++;
                }
            }
        }
        System.out.println("java类型的文件有"+count1+"个");
        System.out.println("doc类型的文件有"+count2+"个");
        System.out.println("txt类型的文件有"+count3+"个");
    }

    public static void main(String[] args) {
        File file = new File("F:\\IDEACodeOFJavaEE\\二重循环\\src");
        count(file);
    }
}
